import React from 'react';

export default class PropertySettingList extends React.Component {
  constructor(props) {
    super(props)
  }

  renderList() {
    var self = this;
    var content = [];
    if (this.props.data && this.props.data.length > 0) {
      this.props.data.forEach(function(data, index) {
        var start_time = data.start_time,
            end_time = data.end_time;
        var start = start_time?(new Date(start_time)).toLocaleTimeString():"",
            end = end_time?(new Date(end_time)).toLocaleTimeString():"";
        content.push((
          <tr>
            <td>{data.name}</td>
            <td>{data.appId}</td>
            <td>{data.province+" "+data.city+" "+data.street}</td>
            <td>{start}</td>
            <td>{end}</td>
            <td>{data.telephone}</td>
            <td>
              {
                // <a onClick={(event)=>self.props.onDeleteClick(index)}>删除</a>
              }
              <a className="edit" onClick={(event)=>self.props.onEditClick(index)}>编辑</a>
              <a className="edit" onClick={(event)=>self.props.onTemplateEdit(data)}>模板配置</a>
              {
                <a className="edit" onClick={(event)=>self.props.onVacationClick(data)}>假期配置</a>
              }
            </td>
          </tr>
        ))
      })
    }

    return content
  }

  render() {
    return(
      <div className="Property-setting-list setting-list">
        <table className="table">
          <thead>
            <tr className="table-title">
              <th>名称</th>
              <th>微信号</th>
              <th>地址</th>
              <th>开始时间</th>
              <th>结束时间</th>
              <th>电话</th>
              <th>编辑</th>
            </tr>
          </thead>
          <tbody>
            {this.renderList()}
          </tbody>
        </table>
      </div>
    )
  }
}
